package com.penghk.springbootdemo.mq.direct;


import com.penghk.springbootdemo.entity.User;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 *性能排序：fanout > direct >> topic。比例大约为11：10：6
 *
 * 任何发送到Direct Exchange的消息都会被转发到RouteKey中指定的Queue。

 1.一般情况可以使用rabbitMQ自带的Exchange：”"(该Exchange的名字为空字符串，下文称其为default Exchange)。

 2.这种模式下不需要将Exchange进行任何绑定(binding)操作

 3.消息传递时需要一个“RouteKey”，可以简单的理解为要发送到的队列名字。

 4.如果vhost中不存在RouteKey中指定的队列名，则该消息会被抛弃。

 The default exchange is implicitly bound to every queue, with a routing key equal to the queue name.
 It it not possible to explicitly bind to, or unbind from the default exchange. It also cannot be deleted.
 *
 */
@Component
public class Sender1 {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    private int i = 0;

    public void send() {
        i++;
        String context = "sender1 : hello " + i;
        this.rabbitTemplate.convertAndSend("hello", context);
    }

    public void sendEntity() {
        i++;
        User user = new User("tony" ,12);
        this.rabbitTemplate.convertAndSend("userQueue", user);
    }

}
